const Mock = require('mockjs')

const List = [{
    "id": 1,
    "timestamp": 1587484800,
    "author": "刘博",
    "title": "上海逸轩网络科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-04-22",
    "pageviews": "10万元人民币"
}, {
    "id": 2,
    "timestamp": 1583484800,
    "author": "陈小贞",
    "title": "上海璇霄餐饮管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2018-04-17",
    "pageviews": "10万元人民币"
}, {
    "id": 3,
    "timestamp": 1589990400,
    "author": "秦杲",
    "title": "上海明梓商务咨询事务所",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-21",
    "pageviews": "10万元人民币"
}, {
    "id": 4,
    "timestamp": 1589299200,
    "author": "徐亚豪",
    "title": "上海德寐贸易有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 5,
    "timestamp": 1589299200,
    "author": "雷玉龙",
    "title": "上海偶唐教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 6,
    "timestamp": 1589299200,
    "author": "葛鹏冲",
    "title": "上海尧曳企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 7,
    "timestamp": 1589299200,
    "author": "王永萍",
    "title": "上海炬佑酒店管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 8,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海嵋杉企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 9,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海铪眺废旧物资回收有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 10,
    "timestamp": 1588867200,
    "author": "陈璐",
    "title": "上海兰桂奇教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-8",
    "pageviews": "200万元人民币"
}, {
    "id": 11,
    "timestamp": 1587484800,
    "author": "刘博",
    "title": "上海逸轩网络科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-04-22",
    "pageviews": "10万元人民币"
}, {
    "id": 12,
    "timestamp": 1583484800,
    "author": "陈小贞",
    "title": "上海璇霄餐饮管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2018-04-17",
    "pageviews": "10万元人民币"
}, {
    "id": 13,
    "timestamp": 1589990400,
    "author": "秦杲",
    "title": "上海明梓商务咨询事务所",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-21",
    "pageviews": "10万元人民币"
}, {
    "id": 14,
    "timestamp": 1589299200,
    "author": "徐亚豪",
    "title": "上海德寐贸易有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 15,
    "timestamp": 1589299200,
    "author": "雷玉龙",
    "title": "上海偶唐教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 16,
    "timestamp": 1589299200,
    "author": "葛鹏冲",
    "title": "上海尧曳企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 17,
    "timestamp": 1589299200,
    "author": "王永萍",
    "title": "上海炬佑酒店管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 18,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海嵋杉企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 19,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海铪眺废旧物资回收有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 20,
    "timestamp": 1588867200,
    "author": "陈璐",
    "title": "上海兰桂奇教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-8",
    "pageviews": "200万元人民币"
}, {
    "id": 21,
    "timestamp": 1587484800,
    "author": "刘博",
    "title": "上海逸轩网络科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-04-22",
    "pageviews": "10万元人民币"
}, {
    "id": 22,
    "timestamp": 1583484800,
    "author": "陈小贞",
    "title": "上海璇霄餐饮管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2018-04-17",
    "pageviews": "10万元人民币"
}, {
    "id": 23,
    "timestamp": 1589990400,
    "author": "秦杲",
    "title": "上海明梓商务咨询事务所",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-21",
    "pageviews": "10万元人民币"
}, {
    "id": 24,
    "timestamp": 1589299200,
    "author": "徐亚豪",
    "title": "上海德寐贸易有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 25,
    "timestamp": 1589299200,
    "author": "雷玉龙",
    "title": "上海偶唐教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 26,
    "timestamp": 1589299200,
    "author": "葛鹏冲",
    "title": "上海尧曳企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 27,
    "timestamp": 1589299200,
    "author": "王永萍",
    "title": "上海炬佑酒店管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 28,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海嵋杉企业管理有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 29,
    "timestamp": 1589299200,
    "author": "陈朋修",
    "title": "上海铪眺废旧物资回收有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-13",
    "pageviews": "100万元人民币"
}, {
    "id": 30,
    "timestamp": 1588867200,
    "author": "陈璐",
    "title": "上海兰桂奇教育科技有限公司",
    "city": "上海市",
    "area": "闵行区",
    "status": "存续",
    "display_time": "2020-05-8",
    "pageviews": "200万元人民币"
}]
const count = 30

const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

// for (let i = 0; i < count; i++) {
//     List.push(Mock.mock({
//         id: '@increment',
//         timestamp: +Mock.Random.date('T'),
//         author: '@first',
//         reviewer: '@first',
//         title: '@title(5, 10)',
//         content_short: 'mock data',
//         content: baseContent,
//         forecast: '@float(0, 100, 2, 2)',
//         importance: '@integer(1, 3)',
//         'type|1': ['CN', 'US', 'JP', 'EU'],
//         'status|1': ['published', 'draft'],
//         display_time: '@datetime',
//         comment_disabled: true,
//         pageviews: '@integer(300, 5000)',
//         image_uri,
//         platforms: ['a-platform']
//     }))
// }
module.exports = [{
        url: '/vue-element-admin/article/list',
        type: 'get',
        response: config => {
            const { importance, type, title, page = 1, limit = 20, sort } = config.query

            let mockList = List.filter(item => {
                if (importance && item.importance !== +importance) return false
                if (type && item.type !== type) return false
                if (title && item.title.indexOf(title) < 0) return false
                return true
            })

            if (sort === '-id') {
                mockList = mockList.reverse()
            }

            const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

            return {
                code: 20000,
                data: {
                    total: mockList.length,
                    items: pageList
                }
            }
        }
    },

    {
        url: '/vue-element-admin/article/detail',
        type: 'get',
        response: config => {
            const { id } = config.query
            for (const article of List) {
                if (article.id === +id) {
                    return {
                        code: 20000,
                        data: article
                    }
                }
            }
        }
    },

    {
        url: '/vue-element-admin/article/pv',
        type: 'get',
        response: _ => {
            return {
                code: 20000,
                data: {
                    pvData: [
                        { key: 'PC', pv: 1024 },
                        { key: 'mobile', pv: 1024 },
                        { key: 'ios', pv: 1024 },
                        { key: 'android', pv: 1024 }
                    ]
                }
            }
        }
    },

    {
        url: '/vue-element-admin/article/create',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    },

    {
        url: '/vue-element-admin/article/update',
        type: 'post',
        response: _ => {
            return {
                code: 20000,
                data: 'success'
            }
        }
    }
]